/**
 * Copyright &copy; 2012-2013 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 */
package com.otod.commons.utils;


import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.BitSet;
import java.util.Calendar;
import java.util.Date;

import org.apache.commons.lang3.time.DateFormatUtils;

/**
 * 日期工具类, 继承org.apache.commons.lang.time.DateUtils类
 *
 * @author ThinkGem
 * @version 2013-3-15
 */
public class DateUtils extends org.apache.commons.lang3.time.DateUtils {

    private static String[] parsePatterns = {"yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm",
            "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm"};

    /**
     * 得到当前日期
     * @return Date
     */
    public static Date getCurrentDate() {
        return new Date();
    }
    
    
    
    /**
     * 得到当前日期字符串 格式（yyyy-MM-dd）
     */
    public static String getDate() {
    	return getDate("yyyy-MM-dd");
    }

    /**
     * 得到当前日期字符串 格式（yyyy-MM-dd） pattern可以为："yyyy-MM-dd" "HH:mm:ss" "E"
     */
    public static String getDate(String pattern) {
        return DateFormatUtils.format(new Date(), pattern);
    }

    /**
     * 得到日期字符串 默认格式（yyyy-MM-dd） pattern可以为："yyyy-MM-dd" "HH:mm:ss" "E"
     */
    public static String formatDate(Date date, Object... pattern) {
    	if(date == null){
    		return "";
    	}
        String formatDate = "";
        if (pattern != null && pattern.length > 0) {
            formatDate = DateFormatUtils.format(date, pattern[0].toString());
        } else {
            formatDate = DateFormatUtils.format(date, "yyyy-MM-dd");
        }
        return formatDate;
    }

    /**
     * 得到当前时间字符串 格式（HH:mm:ss）
     */
    public static String getTime() {
        return formatDate(new Date(), "HH:mm:ss");
    }

    /**
     * 得到当前日期和时间字符串 格式（yyyy-MM-dd HH:mm:ss）
     */
    public static String getDateTime() {
        return formatDate(new Date(), "yyyy-MM-dd HH:mm:ss");
    }

    /**
     * 得到当前年份字符串 格式（yyyy）
     */
    public static String getYear() {
        return formatDate(new Date(), "yyyy");
    }

    /**
     * 得到当前月份字符串 格式（MM）
     */
    public static String getMonth() {
        return formatDate(new Date(), "MM");
    }

    /**
     * 得到当天字符串 格式（dd）
     */
    public static String getDay() {
        return formatDate(new Date(), "dd");
    }

    /**
     * 得到当前星期字符串 格式（E）星期几
     */
    public static String getWeek() {
        return formatDate(new Date(), "E");
    }

    /**
     * 日期型字符串转化为日期 格式
     * { "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm",
     * "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm" }
     */
    public static Date parseDate(Object str) {
        if (str == null) {
            return null;
        }
        try {
            return parseDate(str.toString(), parsePatterns);
        } catch (ParseException e) {
            return null;
        }
    }

    /**
     * 获取过去的天数
     *
     * @param date
     * @return
     */
    public static long pastDays(Date date) {
        long t = new Date().getTime() - date.getTime();
        return t / (24 * 60 * 60 * 1000);
    }



	/**
	 * 得到当前时间	
	 * @return	Date
	 * @author 邱季
	 */
	public static Date getCurrentTimestamp(){
		return new Date();
	}
	
	/**
	 * 得到当前时间
	 * @param pattern	日期格式
	 * @return
	 */
	public static String getCurDate(String pattern){
		Date date = new Date();
		DateFormat df = new SimpleDateFormat(pattern);
		df.setLenient(false);
		return df.format(date);
	}
	
	
	/**
	 * 得到当前yyyyMMddHHmmss格式时间
	 * @return	yyyyMMddHHmmss字符串
	 * @author 邱季
	 */
	public static String getCurDateTime() {
		return getCurDate("yyyyMMddHHmmss");
	}
	
	
	/**
	 * 得到当前HHmmss格式时间	
	 * @return	HHmmss字符串
	 * @author 邱季
	 */
	public static String getCurTime(){
		return getCurDate("HHmmss");
	}
	
	
	
	/**
	 * 得到当前yyyyMMdd格式日期字符串
	 * @return	yyyyMMdd字符串
	 * @author 邱季
	 */
	public static String getCurDate(){
		Date date = new Date();
		DateFormat df = new SimpleDateFormat("yyyyMMdd");
        df.setLenient(false);
        return df.format(date);
	}
	
	
	/**
	 * 字符串转换为日期
	 * @param dateString	日期串
	 * @param format		转换格式
	 * @return				Date<br/> 转换出错返回null
	 */
	public static Date convert2Date(String dateString, String format) {
		Date date = null;
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
		try {
			date = simpleDateFormat.parse(dateString);
			return date;
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
	}

	
	
	/**
	 * 取得date下一日期
	 * @param dateStr yyyyMMdd格式日期串
	 * @return	下一日期yyyyMMdd串
	 */
	public static String getNextDateStr(String dateStr){
		Date date = getNextDate(dateStr);
		return dateToStr(date, "yyyyMMdd");
	}
    
	
	/**
	 * 取得date下一日期
	 * @param dateStr yyyyMMdd格式日期串
	 * @return	Date 下一日期 
	 */
	public static Date getNextDate(String dateStr){
		Date date = strToDate(dateStr,"yyyyMMdd");
		Calendar ca = Calendar.getInstance();
		ca.setTime(date);
		ca.add(Calendar.DATE, 1);
		return ca.getTime();
	}
	
	 /**
     * 两个日期之间相隔天数   
     * @param dateFrom 	开始日期  yyyyMMdd
     * @param dateEnd　	结束日期	yyyyMMdd
     * @return　天数(int) 开始日期如果大于结束日期则返回负数
	 * @ 
     */
    public static int getDaysBetweenTwoDates(String dateFrom, String dateEnd) {
    	return getDaysBetweenTwoDates(dateFrom,dateEnd,"yyyyMMdd");
    }
    
    
    /**
     * 两个日期之间相隔月数   
     * @param dateFrom 	开始日期  yyyyMMdd
     * @param dateEnd　	结束日期	yyyyMMdd
     * @return　天数(int) 开始日期如果大于结束日期则返回负数
     * @ 
     */
    public static int getMonthsBetweenTwoDates(String dateFrom, String dateEnd) {
    	return getMonthsBetweenTwoDates(dateFrom,dateEnd,"yyyyMMdd");
    }
    
    
    /**
     * 两个日期之间相隔季度数   
     * @param from 		开始日期  yyyyMMdd
     * @param dateFrom　	结束日期	yyyyMMdd
     * @return　天数(int) 开始日期如果大于结束日期则返回负数
     * @ 
     */
    public static int getQuartersBetweenTwoDates(String dateFrom, String dateEnd) {
    	return getQuartersBetweenTwoDates(dateFrom,dateEnd,"yyyyMMdd");
    }
    
    /**
     * 两个日期之间相隔年数   
     * @param dateFrom	开始日期 	yyyyMMdd
     * @param dateEnd　	结束日期	yyyyMMdd
     * @return　天数(int) 开始日期如果大于结束日期则返回负数
     * @ 
     */
    public static int getYearsBetweenTwoDates(String dateFrom, String dateEnd) {
    	return getYearsBetweenTwoDates(dateFrom,dateEnd,"yyyyMMdd");
    }
    
    /**
     * 两个日期之间相隔天数   
     * @param dateFrom 开始日期  
     * @param dateEnd　结束日期	
     * @param pattrn　日期格式	
     * @return　天数(int) 开始日期如果大于结束日期则返回负数
     * @ 
     */
    public static int getDaysBetweenTwoDates(String dateFrom, String dateEnd,String pattrn) {
    	Date dtFrom = null;
    	Date dtEnd = null;
    	dtFrom = strToDate(dateFrom, pattrn);
    	dtEnd = strToDate(dateEnd, pattrn);
//    	if(dtFrom==null){
//    		throw new AppException("开始日期不能为空！");
//    	}
//    	if(dtEnd==null){
//    		throw new AppException("结束日期不能为空！");
//    	}
    	return getDaysBetweenTwoDates(dtFrom, dtEnd);
    }
    
    /**
     * 两个日期之间相隔月数   
     * @param from 开始日期  
     * @param to　结束日期	
     * @param pattrn　日期格式	
     * @return　天数(int) 开始日期如果大于结束日期则返回负数
     * @ 
     */
    public static int getMonthsBetweenTwoDates(String dateFrom, String dateEnd,String pattrn) {
    	Date dtFrom = null;
    	Date dtEnd = null;
    	dtFrom = strToDate(dateFrom, pattrn);
    	dtEnd = strToDate(dateEnd, pattrn);
//    	if(dtFrom==null){
//    		throw new AppException("开始日期不能为空！");
//    	}
//    	if(dtEnd==null){
//    		throw new AppException("结束日期不能为空！");
//    	}
//    	if(Integer.valueOf(dateFrom)>Integer.valueOf(dateEnd)){
//    		throw new AppException("开始日期大于结束日期！");
//    	}
    	int startYear = Integer.valueOf(dateFrom.substring(0, 4));
    	int startMonth = Integer.valueOf(dateFrom.substring(5, 6));
    	int startDay = Integer.valueOf(dateFrom.substring(7, 8));
    	int endYear = Integer.valueOf(dateEnd.substring(0, 4));
    	int endMonth = Integer.valueOf(dateEnd.substring(5, 6));
    	int endDay = Integer.valueOf(dateEnd.substring(7, 8));
    	
    	int stayMonths = 0;
    	
    	if(endYear>=startYear){
    		int a = endYear-startYear;
    		if(a>0){
    			stayMonths = a*12;
    		}
    		if(endMonth>=startMonth && endDay>=startDay){
    			int b = endMonth - startMonth;
    			stayMonths = stayMonths+b;
    		}else if(endMonth>=startMonth && endDay<startDay){
    			int b = endMonth - startMonth-1;
    			stayMonths = stayMonths+b;
    		}else if(endMonth<startMonth && endDay>=startDay){
    			int b = startMonth-endMonth;
    			stayMonths = stayMonths-b;
    		}else if(endMonth<startMonth && endDay<startDay){
    			int b = startMonth-endMonth-1;
    			stayMonths = stayMonths-b;
    		}
    	}   	
    	return stayMonths;
    }
    
    /**
     * 两个日期之间相隔季度数   
     * @param from 开始日期  
     * @param to　结束日期	
     * @param pattrn　日期格式	
     * @return　天数(int) 开始日期如果大于结束日期则返回负数
     * @ 
     */
    public static int getQuartersBetweenTwoDates(String dateFrom, String dateEnd,String pattrn) {
    	Date dtFrom = null;
    	Date dtEnd = null;
    	dtFrom = strToDate(dateFrom, pattrn);
    	dtEnd = strToDate(dateEnd, pattrn);
//    	if(dtFrom==null){
//    		throw new AppException("开始日期不能为空！");
//    	}
//    	if(dtEnd==null){
//    		throw new AppException("结束日期不能为空！");
//    	}
//    	if(Integer.valueOf(dateFrom)>Integer.valueOf(dateEnd)){
//    		throw new AppException("开始日期大于结束日期！");
//    	}
    	int startYear = Integer.valueOf(dateFrom.substring(0, 4));
    	int startMonth = Integer.valueOf(dateFrom.substring(5, 6));
    	int startDay = Integer.valueOf(dateFrom.substring(7, 8));
    	int endYear = Integer.valueOf(dateEnd.substring(0, 4));
    	int endMonth = Integer.valueOf(dateEnd.substring(5, 6));
    	int endDay = Integer.valueOf(dateEnd.substring(7, 8));
    	
    	int stays = 0;
    	
    	if(endYear>=startYear){
    		int a = endYear-startYear;
    		if(a>0){
    			stays = a*4;
    		}
    		if(endMonth>=startMonth && endDay>=startDay){
    			int b = endMonth - startMonth;
    			if(b>0){
    				double asd = ArithUtil.div(b,3,2);
        			int d = (int)asd;
        			stays = stays+d;
    			}
    		}else if(endMonth>=startMonth && endDay<startDay){
    			int b = endMonth - startMonth-1;
    			if(b>=0){
    				double asd = ArithUtil.div(b,3,2);
        			int d = (int)asd;
        			stays = stays+d;
    			}else{
    				stays = stays-1;
    			}
    		}else if(endMonth<startMonth && endDay>=startDay){
    			int b = startMonth - endMonth-1;
    			if(b>0){
    				double asd = ArithUtil.div(b,3,2);
        			int d = (int)asd;
        			stays = stays-d-1;
    			}else{
    				stays = stays-1;
    			}
    		}else if(endMonth<startMonth && endDay<startDay){
    			int b = startMonth - endMonth;
    			if(b>0){
    				double asd = ArithUtil.div(b,3,2);
        			int d = (int)asd;
        			stays = stays-d-1;
    			}
    		}
    	}   	
    	return stays;
    }
    
    /**
     * 两个日期之间相隔年数   
     * @param from 开始日期  
     * @param to　结束日期	
     * @param pattrn　日期格式	
     * @return　天数(int) 开始日期如果大于结束日期则返回负数
     * @ 
     */
    public static int getYearsBetweenTwoDates(String dateFrom, String dateEnd,String pattrn) {
    	Date dtFrom = null;
    	Date dtEnd = null;
    	dtFrom = strToDate(dateFrom, pattrn);
    	dtEnd = strToDate(dateEnd, pattrn);
//    	if(dtFrom==null){
//    		throw new AppException("开始日期不能为空！");
//    	}
//    	if(dtEnd==null){
//    		throw new AppException("结束日期不能为空！");
//    	}
//    	if(Integer.valueOf(dateFrom)>Integer.valueOf(dateEnd)){
//    		throw new AppException("开始日期大于结束日期！");
//    	}
    	int startYear = Integer.valueOf(dateFrom.substring(0, 4));
    	int startMonth = Integer.valueOf(dateFrom.substring(5, 6));
    	int startDay = Integer.valueOf(dateFrom.substring(7, 8));
    	int endYear = Integer.valueOf(dateEnd.substring(0, 4));
    	int endMonth = Integer.valueOf(dateEnd.substring(5, 6));
    	int endDay = Integer.valueOf(dateEnd.substring(7, 8));
    	
    	int stays = 0;
    	
    	if(endYear>=startYear){
    			stays = endYear-startYear;
    			if(endMonth>=startMonth && endDay<startDay){
        			int b = endMonth - startMonth-1;
        			if(b<0){
        				stays = stays-1;
        			}
        		}else if(endMonth<startMonth){
        			stays = stays-1;
        		}
    	}   	
    	return stays;
    }
    
    /**
     * 两个日期之间相隔天数   
     * @param dateFrom 开始日期  
     * @param dateEnd　结束日期	
     * @param pattrn　日期格式	
     * @return　天数(int) 开始日期如果大于结束日期则返回负数
     */
    public static int getDaysBetweenTwoDates(Date dateFrom, Date dateEnd){
    	if(dateFrom==null || dateEnd==null){
    		return 0;
    	}
    	long begin = dateFrom.getTime();
    	long end = dateEnd.getTime();
    	long inter = end - begin;
    	
    	long dateMillSec = 86400000;//24 * 60 * 60 * 1000;
    	
    	long dateCnt =  inter / dateMillSec;
    	
    	long remainder = inter % dateMillSec;
    	
    	if (remainder != 0) {
    		dateCnt++;
    	}
    	return Integer.parseInt(String.valueOf(dateCnt));
    }
    
    
    

    /**
     * 日期转换为字符串
     * @param date 	被转换时间
     * @param patrn	转换格式
     * @return	String
     */
	public static String dateToStr(Date date,String patrn){
		DateFormat df = new SimpleDateFormat(patrn);
        df.setLenient(false);
        return df.format(date);
	}
	
	/**
	 * 日期字符串根据patrn转换为日期格式
	 * @param dateStr   日期字符串
	 * @param patrn		格式
	 * @return
	 */
	public static Date strToDate(String dateStr,String patrn){
		DateFormat dateFormat = new SimpleDateFormat(patrn);
		dateFormat.setLenient(false);
		try {
			Date day = dateFormat.parse(dateStr);
		    return day; 
		} catch (Exception e) {
		    e.printStackTrace();
		    return null;
		}

	}
	
	/**
	 * yyyyMMdd的日期转换为yyyy+三位数的DAY_OF_YEAR
	 * @param dateStr	yyyyMMdd的日期字符串
	 * @return			yyyy+三位数的当天是一年中的第几天
	 */
	public static String strDateToDayOfYear(String dateStr){
		Date date = strToDate(dateStr, "yyyyMMdd");
		Calendar ca = Calendar.getInstance();
		ca.setTime(date);
		int dayOfYear = ca.get(Calendar.DAY_OF_YEAR);
		int year = ca.get(Calendar.YEAR);
		String str = "" + year;
		if(dayOfYear<10){
			str += "00"+dayOfYear;
		}else if(dayOfYear <100){
			str += "0"+dayOfYear;
		}else{
			str += dayOfYear;
		}
		return str;
	}
	
	
	/**
	 * 把sPatrn格式的字符串转换为dPatrn格式的日期字符串
	 * @param dateStr	日期字符串
	 * @param sPatrn	源dateStr格式
	 * @param dPatrn	要转换为的格式
	 * @return	dPatrn格式的日期字符串
	 */
	public static String formatStrDate(String dateStr,String sPatrn,String dPatrn){
		Date date = strToDate(dateStr, sPatrn);
		return dateToStr(date, dPatrn);
	}
	
	
	
	
    /**
     * 获得指定日期的前后几天<br/>
     * @param origDate		指定日期
     * @param date			天数（正数表示后几天 负数表示前几天）
     * @return	yyyyMMdd	指定日期 + days的日期
     */
    public static String getDateBefore(String origDate,int days){
    	Date date = null;
		try {
			date = new SimpleDateFormat("yyyyMMdd").parse(origDate);
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
    	return dateToStr(getDateBefore(date, days), "yyyyMMdd");
    }
    
    
    /**
     * 获得指定日期的前后几天
     * @param origDate		指定日期
     * @param date			天数（正数表示后几天 负数表示前几天）
     * @return	Date		指定日期 + days的日期
     */
    public static Date getDateBefore(Date origDate,int days){
    	Calendar cal = Calendar.getInstance();
    	cal.setTime(origDate);
    	cal.set(Calendar.DATE, cal.get(Calendar.DATE) + days);
    	return cal.getTime();
    }
    
	/**
	   * 将日期串转成Timestamp
		 * @param strDate
		 * @return
		 */
	public static Timestamp getTimestampByString(String strDate)
	{
		if (strDate == null)
			return null;

		if (strDate.indexOf(".") >= 0)
			strDate = strDate.substring(0, strDate.indexOf(".")).trim();
		while (strDate.indexOf("-") >= 0)
		{
			StringBuffer strbTmp = new StringBuffer(strDate);
			strDate = strbTmp.deleteCharAt(strDate.indexOf("-")).toString();
		}
		while (strDate.indexOf(" ") >= 0)
		{
			StringBuffer strbTmp = new StringBuffer(strDate);
			strDate = strbTmp.deleteCharAt(strDate.indexOf(" ")).toString();
		}
		while (strDate.indexOf(":") >= 0)
		{
			StringBuffer strbTmp = new StringBuffer(strDate);
			strDate = strbTmp.deleteCharAt(strDate.indexOf(":")).toString();
		}

		if (strDate == null
			|| strDate.trim().equals("")
			|| strDate.length() > 14
			|| strDate.length() < 8)
		{
			return null;
		}
		int intYear = 0;
		int intMonth = 0;
		int intDate = 0;
		int intHour = 0;
		int intMinute = 0;
		int intSencond = 0;

		if (strDate.length() == 8)
		{
			intYear = Integer.parseInt(strDate.substring(0, 4));
			intMonth = Integer.parseInt(strDate.substring(4, 6)) - 1;
			intDate = Integer.parseInt(strDate.substring(6, 8));
		}
		else if (strDate.length() == 10)
		{
			intYear = Integer.parseInt(strDate.substring(0, 4));
			intMonth = Integer.parseInt(strDate.substring(4, 6)) - 1;
			intDate = Integer.parseInt(strDate.substring(6, 8));
			intHour = Integer.parseInt(strDate.substring(8, 10));
		}
		else if (strDate.length() == 12)
		{
			intYear = Integer.parseInt(strDate.substring(0, 4));
			intMonth = Integer.parseInt(strDate.substring(4, 6)) - 1;
			intDate = Integer.parseInt(strDate.substring(6, 8));
			intHour = Integer.parseInt(strDate.substring(8, 10));
			intMinute = Integer.parseInt(strDate.substring(10, 12));
		}
		else if (strDate.length() == 14)
		{
			intYear = Integer.parseInt(strDate.substring(0, 4));
			intMonth = Integer.parseInt(strDate.substring(4, 6)) - 1;
			intDate = Integer.parseInt(strDate.substring(6, 8));
			intHour = Integer.parseInt(strDate.substring(8, 10));
			intMinute = Integer.parseInt(strDate.substring(10, 12));
			intSencond = Integer.parseInt(strDate.substring(12, 14));
		}
		else
		{
			return null;
		}
		Calendar tmpCal = Calendar.getInstance();
		tmpCal.set(intYear, intMonth, intDate, intHour, intMinute, intSencond);
		return new java.sql.Timestamp(tmpCal.getTime().getTime() / 1000 * 1000);
	}
	
	/**
	 * 返回两个指定日期相差的天数（第二个参数－第一个参数）
	 * @param firstDate    起始日期
	 * @param secondDate   终止日期
	 * @return             差值
	 */
	public static Long getDateDiff(
		java.sql.Date firstDate,
		java.sql.Date secondDate)
	{
		if ((firstDate == null) || (secondDate == null))
		{
			return null;
		}
		return new Long(
			(secondDate.getTime() - firstDate.getTime()) / (24 * 60 * 60 * 1000));
	}
    
	/**
     * 将当前日期去掉时分秒，得到java.util.Date对象
     * @return
     */
    public static Date buildSqlDate(){
        Date today;
        try {
            SimpleDateFormat sdfrmt = new SimpleDateFormat("yyyy-MM-dd");
            java.util.Date utilDate = sdfrmt.parse(sdfrmt.format(new java.util.Date()));
            today = new Date(utilDate.getTime());
        } catch (ParseException e) {
            today = new Date(System.currentTimeMillis());
            e.printStackTrace();
        }
        return today;
    }
    
    /**
     * 生成java.util.BitSet
     * @param stream
     * @return
     */
    public static BitSet buildBitSet(String stream){
        if (stream == null){
            return new BitSet(16);
        }
        int len = stream.length();
        BitSet bits = new BitSet(len);
        for (int i=0; i<len; i++){
            bits.set(i+1, (stream.charAt(i)=='1'?true:false));
        }
        return bits;
    }
    
    public static String setStatusBit(int bit, String status){
        if (status == null){
            throw new IllegalArgumentException("The argument 'status' must not be null");
        }else if (status.length() < bit){
            throw new IllegalArgumentException("The argument 'bit' must be less than "+status.length());
        }
        
        return new StringBuffer(status.substring(0, bit-1))
            .append("1").append(status.substring(bit))
            .toString();
    }
    public static String clearStatusBit(int bit, String status){
        if (status == null){
            throw new IllegalArgumentException("The argument 'status' must not be null");
        }else if (status.length() < bit){
            throw new IllegalArgumentException("The argument 'bit' must be less than "+status.length());
        }
        
        return new StringBuffer(status.substring(0, bit-1))
            .append("0").append(status.substring(bit))
            .toString();
    }
    
    /**
     * 根据年月得到月末日期  
     * @param String dateMonth yyyyMM
     * @return　String dateEndMonth yyyyMMdd
     * @ 
     */
    public static String getMonthEndDate(String dateMonth) {
    	Date date=strToDate(dateMonth, "yyyyMM");
    	Calendar calendar=Calendar.getInstance();
    	calendar.setTime(date);
    	int end=calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    	return dateMonth+String.valueOf(end);
    }
    
    /**
     * 取得一天的最后时间点
     * @param date	传入date
     * @return
     * @
     */
    public static Date getDayOfLastTime(Date date) {
		Calendar cal =  Calendar.getInstance();
		cal.setTime(date);
		cal.set(Calendar.HOUR_OF_DAY, 0);
		cal.set(Calendar.MINUTE, 0);
		cal.set(Calendar.SECOND, 0);
		cal.set(Calendar.MILLISECOND,0);
		cal.set(Calendar.DATE, cal.get(Calendar.DATE)+1);
		return new Date(cal.getTimeInMillis() -1);
    }
    
    /**
     * 取得一天的最早时间点
     * @param date	传入date
     * @return
     * @
     */
    public static Date getDayOfFirstTime(Date date) {
    	Calendar cal =  Calendar.getInstance();
    	cal.setTime(date);
    	cal.set(Calendar.HOUR_OF_DAY, 0);
    	cal.set(Calendar.MINUTE, 0);
    	cal.set(Calendar.SECOND, 0);
    	cal.set(Calendar.MILLISECOND,0);
    	cal.set(Calendar.DATE, cal.get(Calendar.DATE));
    	return new Date(cal.getTimeInMillis());
    }
    
    
    /**
     * 转换时间
     * @param time
     * @return
     */
    public static Date longToDate(long time) {
    	return new Date(time * 1000);
    }
}
